//
//  VideoFeed.swift
//  Tiktok
//
//  Created by xmd on 10/1/20.
//

import Foundation

struct VideoFeed: Codable {
    var aweme_list: [Aweme]
}

struct Aweme: Codable, Identifiable {
    var id: String {
        self.awemeId
    }
    var awemeId: String
    var desc:String?
    var createTime:Date
    var author: Author
    var music: Music?
    var video: Video
    var statistics: Statistics
    var authorUserId: Int
    var rate: Int
    var isTop: Int
    var labelTop: Resource?
    var isAds: Bool
    var duration: Int?
    
    enum CodingKeys: String, CodingKey {
        case awemeId = "aweme_id"
        case desc
        case createTime = "create_time"
        case author
        case music
        case video
        case statistics
        case authorUserId = "author_user_id"
        case rate
        case isTop = "is_top"
        case labelTop = "label_top"
        case isAds = "is_ads"
        case duration
    }
}


struct Author: Codable {
    var uid: String
    var nickName: String
    var signature: String?
    var avatarLarger: Resource
    var avatarThumb: Resource
    var avatarMedium: Resource
    var birthday: String
    var isVerified: Bool
    var followStatus: Int
    var awemeCount: Int?
    var followingCount: Int?
    var followerCount: Int?
    var favoritingCount: Int?
    var totalFavorited: Int?
    var constellation: Int
    
    enum CodingKeys: String, CodingKey {
        case uid
        case nickName = "nickname"
        case signature
        case avatarLarger = "avatar_larger"
        case avatarThumb = "avatar_thumb"
        case avatarMedium = "avatar_medium"
        case birthday
        case isVerified = "is_verified"
        case followStatus = "follow_status"
        case awemeCount = "aweme_count"
        case followingCount = "following_count"
        case followerCount = "follower_count"
        case favoritingCount = "favoriting_count"
        case totalFavorited = "total_favorited"
        case constellation
    }
}

struct Resource: Codable {
    var uri: String
    var urlList: [String]
    var width: Int?
    var height: Int?
    
    enum CodingKeys: String, CodingKey {
        case uri
        case urlList = "url_list"
        case width
        case height
    }
}


struct Music: Codable {
    var id: Int
    var idStr: String
    var title: String
    var author: String
    var album: String?
    var coverHd: Resource
    var coverLarge: Resource
    var coverMedium: Resource
    var coverThumb: Resource
    var playUrl: Resource
    var ownerId: String?
    var ownerNickname: String
    var isOriginal: Bool
    var userCount: Int
    var duration: Int
    
    enum CodingKeys: String, CodingKey {
        case id
        case idStr = "id_str"
        case title
        case author
        case album
        case coverHd = "cover_hd"
        case coverLarge = "cover_large"
        case coverMedium = "cover_medium"
        case coverThumb = "cover_thumb"
        case playUrl = "play_url"
        case ownerId = "owner_id"
        case ownerNickname = "owner_nickname"
        case isOriginal = "is_original"
        case userCount = "user_count"
        case duration
    }
}

struct Video: Codable {
    var playAddr: Resource
    var cover: Resource
    var height: Int?
    var width: Int?
    var dynamicCover: Resource
    var originCover: Resource
    var ratio: String
    var downloadAddr: Resource
    var hasWatermark: Bool
    var playAddrLowbr: Resource
    var duration: Int?
    
    enum CodingKeys: String, CodingKey {
        case playAddr = "play_addr"
        case cover
        case height
        case width
        case dynamicCover = "dynamic_cover"
        case originCover = "origin_cover"
        case ratio
        case downloadAddr = "download_addr"
        case hasWatermark = "has_watermark"
        case playAddrLowbr = "play_addr_lowbr"
        case duration
    }
}


struct Statistics: Codable {
    var awemeId: String
    var commentCount: Int
    var diggCount: Int
    var downloadCount: Int
    var playCount: Int
    var shareCount: Int
    var forwardCount: Int
    
    enum CodingKeys: String, CodingKey {
        case awemeId = "aweme_id"
        case commentCount = "comment_count"
        case diggCount = "digg_count"
        case downloadCount = "download_count"
        case playCount = "play_count"
        case shareCount = "share_count"
        case forwardCount = "forward_count"
    }
}
